package com.googlecode.gwtbb.client.shared.util;

import com.googlecode.gwtbb.client.shared.entity.picture.Picture;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Aug 6, 2008
 */
public class PictureUtils {
	public static double getAspectRatio(int width, int height) {
		return height != 0 ? ((double)width) / height : Float.MAX_VALUE;
	}

	public static String getPicFileName(String base, int width, int height, String extension) {
		return base + "_" + width + "x" + height + StringUtils.EXT_DELIM + extension;
	}

	public static String getServerFileName(Picture picture) {
		String url = picture.getUrl();
		// this will stop working in the year 3000, or if someone puts a 2 in the gwtbb.picture.url.base...
		// i don't care much, as i don't have access to the gwtbb.picture.url.base here.
		return url.substring(url.indexOf('2'));
	}

	private PictureUtils() {
	}
}
